package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ILegalLawyerService;
import com.mdd.admin.validate.LegalLawyerCreateValidate;
import com.mdd.admin.validate.LegalLawyerSearchValidate;
import com.mdd.admin.validate.LegalLawyerStateUpdateValidate;
import com.mdd.admin.validate.LegalLawyerUpdateValidate;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.LegalLawyerDetailVo;
import com.mdd.admin.vo.LegalLawyerListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;

@RestController
@RequestMapping("api/lawyer")
@Api(tags = "律师列表管理")
public class LegalLawyerController {

    @Resource
    ILegalLawyerService iLegalLawyerService;

    @GetMapping("/list")
    @ApiOperation(value="律师列表列表")
    public AjaxResult<PageResult<LegalLawyerListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated LegalLawyerSearchValidate searchValidate) {
        PageResult<LegalLawyerListedVo> list = iLegalLawyerService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="律师列表详情")
    public AjaxResult<LegalLawyerDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        LegalLawyerDetailVo detail = iLegalLawyerService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "律师列表新增")
    @PostMapping("/add")
    @ApiOperation(value="律师列表新增")
    public AjaxResult<Object> add(@Validated @RequestBody LegalLawyerCreateValidate createValidate) {
        iLegalLawyerService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "律师列表编辑")
    @PostMapping("/edit")
    @ApiOperation(value="律师列表编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody LegalLawyerUpdateValidate updateValidate) throws ParseException {
        iLegalLawyerService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "律师列表审核")
    @PostMapping("/editStatus")
    @ApiOperation(value="律师列表审核")
    public AjaxResult<Object> editStatus(@Validated @RequestBody LegalLawyerStateUpdateValidate updateValidate) {
        iLegalLawyerService.editStatus(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "律师列表删除")
    @PostMapping("/del")
    @ApiOperation(value="律师列表删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iLegalLawyerService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
